<?php
include_once 'checkLogin.php';
include_once 'db/li.php';

@$types = dbSelectAll('select id,name from type order by id asc');

@$goods = dbSelectAll('select goods.id as gId,type.id as tId,imgUrl,goods.name as gName,type.name as tName,stockPrice,sellPrice,sellStatus,basicStatus,stock,typeId from goods join type on goods.typeId=type.id order by goods.id asc');

@$noPayOrders = dbSelectAll("select id,name,goodsPrice,payPrice,startDate,payDate from `order` where pay='否'");

@$payOrders = dbSelectAll("select id,name,goodsPrice,payPrice,startDate,payDate from `order` where pay='是'");

@$allOrders = dbSelectAll('select id,name,goodsPrice,payPrice,startDate,payDate,pay from `order`');

@$roleName = dbSelect('select role.name from user join role on user.roleId=role.id where user.id=:id',array('id'=>$_SESSION['userId']));

@$manas = dbSelectAll('select name from management limit 0,4');

?>
<!DOCTYPE html>
<html>
	<head>
      <title>nav</title>
	  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" charset="UTF-8" >
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
      <link href="bootstrap/css/bootstrap-editable.css" rel="stylesheet">
      <link href="bootstrap/css/fileinput.css" rel="stylesheet">
      <link href="bootstrap/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
      <script src="bootstrap/js/jquery-1.11.1.min.js"></script>
      <script src="bootstrap/js/bootstrap.min.js"></script>
      <script src="bootstrap/js/bootstrap-editable.js"></script>
      <script src="bootstrap/js/fileinput.js"></script>
      <script src="bootstrap/js/bootstrap-datetimepicker.min.js"></script>
      <script src="bootstrap/js/bootstrap-datetimepicker.zh-CN.js"></script>
      <!--[if lt IE 9]>
         <script src="bootstrap/js/html5shiv.js"></script>
         <script src="bootstrap/js/respond.min.js"></script>
      <![endif]-->
      <script src="db/dialog.js"></script>
      <script src="db/logOut.js"></script>
      <!--  <script src="db/header.js"></script>-->
      <style>
      	body{ font-family:"楷体"; font-weight:800; font-size:15px; }
      	
      	.goodsImg,.workerImg{ width:50px; height:50px; }
      	
      	#img{ width:100%; height:150px; }					/*index*/
      	#indexGoodsThum *{ text-align:center; margin:5px 0 5px 0; }
      	.thumbnail:hover{ border:1px solid #006000; }
      	#payA{ margin-top:-5px; }
      	#orderImg{ width:100%; height:110px; }
      	.countInput{ width:70px; height:25px; }
      	.billTable{ color:#000000; }
      	.payModal img{ width:100px; height:40px; margin:20px 50px; }
      	.nextCode{ display:inline-block; margin-top:3px; }
      	/*.goodsCaption{ display:none; }*/
      	 
      	.updateGoodsImg,.addGoodsImg{ width:200px; height:200px; }
      	.addGoodsImg{ display:inline-block; margin-left:15px; }
      	.addGoodsGroup{ margin:50px auto; }
      	
      	.delWorker:hover{ color:red; cursor:pointer; }
      	
      	.money{ color:red; font-size:23px; }
      	.incomeTitle{ margin-top:7px; }]
      	
      	.jurisdiction_left{ margin:0; padding:0; }
      	.jurisdiction_left ul li{ list-style:none; font-size:17px; margin:10px 0 0 -48px; border:1px solid #9393FF; border-radius:10px; text-align:center; }
      	.jurisdiction ul li:hover{ background:#9393FF; }
      	.jurisdiction_left ul li,#confirmEdi:hover{ cursor:pointer; }
      	.jurisdiction_right{ display:none; }
      	.noneDiv{ padding-top:30px; font-size:25px; }
      	.jurisdiction_right ul li{ list-style:none; width:100%; height:30px; border:1px solid #9393FF; margin:10px 0 0 -30px; padding-left:10px; line-height:30px; border-radius:8px; }
      </style>
      <script>
      	$.ajaxSetup({
			dataType:'JSON',
			error:function(){
				$.message('消息提示','与服务器交互出错');
			}
        })
		$(function(){
			$('#supCaption').click(function(){
				var roleName = "<?php echo $roleName['name'];?>";
				$.message('关于超市','你以['+roleName+']身份登入');
			});
			<?php foreach($noPayOrders as $noPayOrder){?>
				$('#orderName<?php echo $noPayOrder['id'];?>').click(function(){
					$('.orderCon').css({'display':'block'});
				});
			<?php }?>					
			<?php foreach($goods as $good){?>															//删除商品
				$('#delGoods<?php echo $good['gId'];?>').click(function(){
					$.confirm('删除确认',"你确定要删除商品[<?php echo $good['gName'];?>]");
					$('#confirmBtn').click(function(){
						$.post('del.php',{'id':<?php echo $good['gId'];?>,'name':'goods'},function(o){
							if(!o.status){
								$.message('消息提示',o.info);
								var id = o.id;
								console.log(id);
							}else{
								$('#goodsTr<?php echo $good['gId'];?>').remove();
								dialog.modal('hide');
							}
						});
					});
				});
			<?php }?>
			<?php foreach($types as $type){?>															//删除类型
				$('#deleteType<?php echo $type['id'];?>').click(function(){
					$.confirm('删除确认',"你确定要删除商品[<?php echo $type['name'];?>]");
					$('#confirmBtn').click(function(){
						$.post('del.php',{'id':<?php echo $type['id'];?>,'name':'type'},function(o){
							if(!o.status){
								$.message('消息提示',o.info);
							}else{
								$('#typeTr<?php echo $type['id'];?>').remove();
								dialog.modal('hide');
							}
						});
					});
				});
			<?php }?>
			<?php foreach($allOrders as $allOrder){?>															//删除订单
				$('#delOrder<?php echo $allOrder['id'];?>').click(function(){
					$.confirm('删除确认',"你确定要删除订单[<?php echo $allOrder['name'];?>]");
					$('#confirmBtn').click(function(){
						$.post('del.php',{'id':<?php echo $allOrder['id'];?>,'name':'order'},function(o){
							if(!o.status){
								$.message('消息提示',o.info);
							}else{
								$('#orderTtr<?php echo $allOrder['id'];?>').remove();
								dialog.modal('hide');
							}
						});
					});
				});
			<?php }?>
/*
			var where = $();
			$.post('manaData.php',function(o){
				var manas = o.manas;
				for(var i=0; i<manas.length;i++){
					var mana = manas[i];
					$('#ulId').children().children().eq(i).html(mana.name);
				}
				//console.log(manas);
			});
			//$('#ulId').children().children().html;
			*/
		});  
      </script>
   	</head>
	<body>
   		<nav class='navbar' style='background:#ddd0dd;'>
   			<div class='container'>
   				<div class='navbar-header'>
   					<a class='navbar-brand' href='index.php'>XX超市</a>
   				</div>
   				<div class='collapse navbar-collapse' id='bs-example-navbar-collapse-1'>
   					<ul class='nav navbar-nav'>
   						<li class='dropdown'>
   							<a href='#' class='dropdown-toggle' data-toggle='dropdown' type='button'>商品管理<span class='caret'></span></a>
   							<ul class='dropdown-menu' id='ulId'>
   								<li><a href='goodsList.php'></a></li>
   								<li><a href='addGoodsType.php?addType=goods'></a></li>
   								<li><a href='typeList.php'></a></li>
   								<li><a href='addGoodsType.php?addType=type'></a></li>
   							</ul>
   						</li>
   						
   						
   						
   						
   						
   						
   						
   						
   						
   						<?php if($_SESSION['userId'] == '1'){?>
   							<li class='dropdown'>
	   							<a href='#' class='dropdown-toggle' data-toggle='dropdown' type='button'>职员管理<span class='caret'></span></a>
	   							<ul class='dropdown-menu'>
	   								<li><a href='workerList.php?type=worker'>所有职员</a></li>
	   								<li><a href='addGoodsType.php?addType=worker'>添加职员</a></li>
	   								<li><a href='workerList.php?type=role'>职位列表</a></li>
	   								<li><a href='addGoodsType.php?addType=role'>添加职位</a></li>
	   							</ul>
	   						</li>
   						<?php }?>
   						<li class='dropdown'>
   							<a href='#' class='dropdown-toggle' data-toggle='dropdown' type='button'>商品管理<span class='caret'></span></a>
   							<ul class='dropdown-menu'>
   								<li><a href='goodsList.php'>所有商品</a></li>
   								<li><a href='addGoodsType.php?addType=goods'>添加商品</a></li>
   								<li><a href='typeList.php'>商品类型列表</a></li>
   								<li><a href='addGoodsType.php?addType=type'>添加商品类型</a></li>
   							</ul>
   						</li>
   						<li class='dropdown'>
   							<a href='#' class='dropdown-toggle' data-toggle='dropdown'>价格管理<span class='caret'></span></a>
   							<ul class='dropdown-menu'>
   								<li><a href='goodsList.php?listType=price'>价格列表</a></li>
   							</ul>
   						</li>
   						<li class='dropdown'>
   							<a href='#' class='dropdown-toggle' data-toggle='dropdown'>状态管理<span class='caret'></span></a>
   							<ul class='dropdown-menu'>
   								<li><a href='goodsList.php?listType=status'>状态列表</a></li>
   							</ul>
   						</li>
   						<li class='dropdown'>
   							<a href='#' class='dropdown-toggle' data-toggle='dropdown'>库存管理<span class='caret'></span></a>
   							<ul class='dropdown-menu'>
   								<li><a href='goodsList.php?listType=stock'>库存列表</a></li>
   							</ul>
   						</li>
   						<li class='dropdown'>
   							<a href='#' class='dropdown-toggle' data-toggle='dropdown'>订单管理<span class='caret'></span></a>
   							<ul class='dropdown-menu'>
   								<li><a href="addOrder.php">新建订单</a></li>
   								<li><a href="orderList.php?orderType=all">全部订单</a></li>
   								<li><a href="orderList.php?orderType=now">当前订单</a></li>
   								<li><a href="orderList.php?orderType=history">历史订单</a></li>
   							</ul>
   						</li>
   						<?php if($_SESSION['userId'] == '1'){?>
	   						<li class='dropdown'>
	   							<a href='#' class='dropdown-toggle' data-toggle='dropdown'>营业收入<span class='caret'></span></a>
	   							<ul class='dropdown-menu'>
	   								<li><a href='incomeList.php?incomeType=all'>全部收入</a></li>
	   								<li><a href='incomeList.php?incomeType=year'>年收入</a></li>
	   							</ul>
	   						</li>
   						<?php }?>
   						<li class='dropdown'>
	   							<a href='#' class='dropdown-toggle' data-toggle='dropdown'>权限管理<span class='caret'></span></a>
	   							<ul class='dropdown-menu'>
	   								<li><a href='jurisdiction.php'>权限列表</a></li>
	   							</ul>
	   						</li>
   						<li class='dropdown'>
   							<a href='#' class='dropdown-toggle' data-toggle='dropdown'>登录管理<span class='caret'></span></a>
   							<ul class='dropdown-menu'>
   								<li><a href='changeLogin.php' id='changeLogin'>修改登录信息</a></li>
   								<li><a href='#' id='loginOut'>退出登录</a></li>
   								<li><a href='#' id='supCaption'>关于超市</a></li>
   							</ul>
   						</li>
   					</ul>
   				</div>
   			</div>
	   	</nav>
 